package com.smec.moblie.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.smec.moblie.R;
import com.smec.moblie.activity.FastrepairHistoryDetailActivity;
import com.smec.moblie.bean.MaintenanceFastrepairhisBean;
import com.smec.moblie.view.RippleView;

import java.util.ArrayList;

/**
 * 电梯详情adapter
 * Created by sunyubo on 15/12/23.
 */
public class FastrepairHistoryAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private ArrayList<MaintenanceFastrepairhisBean> maintenanceFastrepairhisBeanList;
    private Context context;

    public FastrepairHistoryAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        maintenanceFastrepairhisBeanList = new ArrayList<MaintenanceFastrepairhisBean>();
    }

    public void setList(ArrayList<MaintenanceFastrepairhisBean> maintenanceFastrepairhisBeanList){
        this.maintenanceFastrepairhisBeanList = maintenanceFastrepairhisBeanList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return maintenanceFastrepairhisBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return maintenanceFastrepairhisBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = inflater.inflate(R.layout.item_elevatordetail, null);
        } else {
            view = convertView;
        }
        TextView textView_workorder_no = (TextView) view.findViewById(R.id.textView_workorder_no);
        TextView textView_report = (TextView) view.findViewById(R.id.textView_report);
        TextView textView_finish_date = (TextView) view.findViewById(R.id.textView_finish_date);
        TextView textView_repair = (TextView) view.findViewById(R.id.textView_repair);
        RippleView fastrepaihislistRippleView = (RippleView)view.findViewById(R.id.fastrepaihislistRippleView);

        fastrepaihislistRippleView.setRippleDuration(100);

        textView_workorder_no.setText(maintenanceFastrepairhisBeanList.get(position).getWorkorder_no());
        textView_report.setText(maintenanceFastrepairhisBeanList.get(position).getReport());
        textView_finish_date.setText(maintenanceFastrepairhisBeanList.get(position).getFinish_date());
        textView_repair.setText(maintenanceFastrepairhisBeanList.get(position).getRepair());

        fastrepaihislistRippleView.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                Intent intent = new Intent(context, FastrepairHistoryDetailActivity.class);
                intent.putExtra("MaintenanceFastrepairhisBean",maintenanceFastrepairhisBeanList.get(position));
                context.startActivity(intent);
            }
        });

        return view;
    }
}
